package com.leilei.web;

import com.leilei.controller.Game;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by yvdedu.com on 2016/11/17.
 */
@WebServlet("/getName")
public class MyServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("UTF-8");
        String callback="1";
        String name = req.getParameter("name");
        if(!name.isEmpty()){
            if(Game.names.contains(name)){
                callback=name+"已经在场上战斗了，换个名字吧！";
            }
        }else {
            callback="名字不能为空";
        }
        resp.getWriter().print(callback);
    }
}
